//
//  ViewController.m
//  Attention
//
//  Created by student on 16/2/18.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"
//1.分析整个引用中总共有哪些对象？罗列出来
    //1.self.view
    //2.4个button
    //3.1个label
    //4.ViewController 对象
    //5.appDelegate对象
    //6.UIAlertView对象
    //
@interface ViewController ()
@property (nonatomic,weak) UILabel *displayLabel;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self setUpBtn];
}

//创建4个按钮 和一个labelView
-(void)setUpBtn{
    for (int i = 0; i < 4; i++) {
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 20+10*(i+1)+100*i , 100, 100)];
        btn.tag = i;
        switch (btn.tag) {
            case 0:
                [btn setTitle:@"简单操作" forState:UIControlStateNormal];
                [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                btn.backgroundColor = [UIColor grayColor];
                //添加点击事件
                [btn addTarget:self action:@selector(didClickBtn:) forControlEvents:UIControlEventTouchUpInside];
                break;
            case 1:
                [btn setTitle:@"多按钮" forState:UIControlStateNormal];
                [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                btn.backgroundColor = [UIColor grayColor];
                [btn addTarget:self action:@selector(didClickBtn:) forControlEvents:UIControlEventTouchUpInside];
                break;
            case 2:
                [btn setTitle:@"用户密码" forState:UIControlStateNormal];
                [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                btn.backgroundColor = [UIColor grayColor];
                [btn addTarget:self action:@selector(didClickBtn:) forControlEvents:UIControlEventTouchUpInside];
                break;
            case 3:
                [btn setTitle:@"操作表" forState:UIControlStateNormal];
                [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                btn.backgroundColor = [UIColor grayColor];
                [btn addTarget:self action:@selector(didClickBtn:) forControlEvents:UIControlEventTouchUpInside];
                break;
            default:
                break;
        }
        [self.view addSubview:btn];
    }
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 500, 375, 40)];
    [label setTextColor:[UIColor blackColor]];
    [label setText:@"显示内容"];
    self.displayLabel = label;
    [self.view addSubview:self.displayLabel];
    
}

//点击事件
-(void)didClickBtn:(UIButton *)sender{
    switch (sender.tag) {
        case 0:
            [self pressBtn1];
            break;
        case 1:
            [self pressBtn2];
            break;
        case 2:
            [self pressBtn3];
            break;
        case 3:
            [self pressBtn4];
            break;
        default:
            break;
    }
}
//点击第一个按钮的事件
-(void)pressBtn1{
    //创建UIAlertController
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"弹出弹框1" message:@"弹出弹框信息" preferredStyle:UIAlertControllerStyleAlert];
    //添加动作按钮
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];    [alertController addAction:sureAction];
    //把alertController显示出来
    [self presentViewController:alertController animated:YES completion:nil];
}
//点击第二个按钮的事件
-(void)pressBtn2{
    //创建alertController
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"弹出弹框2" message:@"吃饭了吗" preferredStyle:UIAlertControllerStyleAlert];
    //添加按钮
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"我还没有吃" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:action1];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"吃过了,吃的是肯德基" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:action2];
    UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"没吃,你想请我吗" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:action3];
    //把alertController显示出来
    [self presentViewController:alertController animated:YES completion:nil];
}
//点击第三个按钮的事件
-(void)pressBtn3{
    //1.创建alertController
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"登陆" message:@"请输入用户名和密码" preferredStyle:UIAlertControllerStyleAlert];
    //2.添加输入框
    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"请输入用户信息";
    }];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"请输入密码";
    }];
    //3.添加按钮
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:cancleAction];
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //把输入的信息显示到label上
        NSString *info = [NSString stringWithFormat:@"用户:%@,密码:%@",alertController.textFields[0].text,alertController.textFields[1].text];
        self.displayLabel.text = info;
        
    }];
    [alertController addAction:sureAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
}
//点击第四个按钮的事件
-(void)pressBtn4{
    //创建sheet
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"你想去哪里吃饭" message:@"请吃饭" preferredStyle:UIAlertControllerStyleActionSheet];
    //添加按钮
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"去KFC" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:action1];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"去卡宾斯基" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:action2];
    UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"去烤鸭馆" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:action3];

    
    [self presentViewController:alertController animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
